package com.example.wangyeming.getuidemo.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.example.wangyeming.getuidemo.application.GetuiApplication;
import com.example.wangyeming.getuidemo.model.WaitBus;
import com.example.wangyeming.getuidemo.utils.MyNotification;
import com.igexin.sdk.PushConsts;

/**
 * Created by wangyeming on 15-6-10.
 */
public class PushDemoReceiver extends BroadcastReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        switch (bundle.getInt(PushConsts.CMD_ACTION)) {
            case PushConsts.GET_MSG_DATA:
                // 获取透传（payload）数据
                byte[] payload = bundle.getByteArray("payload");
                if (payload != null) {
                    String data = new String(payload);
                    Log.d("wym", "发送通知栏消息 " + data);
                    WaitBus waitBus = JSON.parseObject(data, WaitBus.class);
                    Log.d("wym", "waitBus " + waitBus);
                    if(GetuiApplication.getInstance().getIsForeground()) {
                        //nothing to do
                    } else {
                        MyNotification myNotification = new MyNotification(context);
                        if(waitBus != null) {
                            myNotification.sendNotification(waitBus.lineId,
                                    0, MyNotification.NOTIFICATION_STYLE_1,
                                    "线路编号 " + waitBus.lineId, waitBus.context);
                        }
                    }
                }
                break;
            //添加其他case
            //.........
            default:
                break;
        }
    }

}
